﻿using System;
using System.Linq;
using System.Linq.Expressions;
using System.Linq.Dynamic;using System.Text;
using System.Data.Linq;
using System.Transactions;
using LinqToSqlExtensions;using System.ServiceModel;
using System.Collections;
using System.Collections.Generic;
using CardsServer.DAL;

namespace CardsServer.WCF
{
	public partial interface IService
{
[OperationContract]
string SK_I_Add(SK_I model ,int ACID);


[OperationContract]
string SK_I_Update(SK_I model ,int ACID);


[OperationContract]
string SK_IByiid_Delete(int iid,int ACID);


[OperationContract]
SK_I SK_IByiid_Get(int iid,int ACID );


[OperationContract]
List<SK_I> SK_I_Get(string sortBy,int ACID);




}
public partial class Service : IService
{
#region  添加SK_I表数据
/// <summary>
/// 添加SK_I
/// </summary>
/// <param name="model">SK_I实体</param>
/// <returns>空或错误</returns>
public string SK_I_Add(SK_I model,int ACID)
{
if(model.iid==null )
{
return "『收款单收入明细ID』不能为空！";
}
if(model.zftypeid==null )
{
return "『支付方式ID』不能为空！";
}
if(model.jine==null )
{
return "『收入金额』不能为空！";
}
if(model.bankid==null )
{
return "『银行帐号id』不能为空！";
}
if(string.IsNullOrEmpty(model.pid))
{
return "『收款单号』不能为空！";
}
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if(ctx.SK_I.Count(p=>p.iid==model.iid)>0)
{
return "主键已存在！";
}
ctx.SK_I.InsertOnSubmit(model);
ctx.SubmitChanges();
return string.Empty;
}
catch (Exception ex)
{
return " 添加失败!错误详细信息：" + ex.Message;
}
}
}
#endregion

#region  添加SK_I表数据事物用重构
/// <summary>
/// 添加SK_I事物用重构
/// </summary>
/// <param name="model">SK_I实体</param>
/// <returns>空或错误</returns>
private string SK_I_Add(SK_I model,int ACID, CardsServer.DAL.DataClassesDataContext ctx)
{
if(model.iid==null )
{
return "『收款单收入明细ID』不能为空！";
}
if(model.zftypeid==null )
{
return "『支付方式ID』不能为空！";
}
if(model.jine==null )
{
return "『收入金额』不能为空！";
}
if(model.bankid==null )
{
return "『银行帐号id』不能为空！";
}
if(string.IsNullOrEmpty(model.pid))
{
return "『收款单号』不能为空！";
}
if(ctx.SK_I.Count(p=>p.iid==model.iid)>0)
{
return "主键已存在！";
}
ctx.SK_I.InsertOnSubmit(model);
return string.Empty;
}
#endregion



#region  修改SK_I表数据
/// <summary>
/// 修改SK_I
/// </summary>
/// <param name="model">SK_I实体</param>
/// <returns>空或错误</returns>
public string SK_I_Update(SK_I model,int ACID)
{
if(model.iid==null )
{
return "『收款单收入明细ID』不能为空！";
}
if(model.zftypeid==null )
{
return "『支付方式ID』不能为空！";
}
if(model.jine==null )
{
return "『收入金额』不能为空！";
}
if(model.bankid==null )
{
return "『银行帐号id』不能为空！";
}
if(string.IsNullOrEmpty(model.pid))
{
return "『收款单号』不能为空！";
}
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if(ctx.SK_I.Count(p=>p.iid==model.iid)!= 1)
{
return "未找到指定记录或记录不唯一！";
}
SK_I SK_Imodel=ctx.SK_I.Single(p => p.iid==model.iid);
if(model.iid!=null )
{
SK_Imodel.iid=model.iid;
}
if(!string.IsNullOrEmpty(model.pid))
{
SK_Imodel.pid=model.pid;
}
if(model.bankid!=null )
{
SK_Imodel.bankid=model.bankid;
}
if(model.jine!=null )
{
SK_Imodel.jine=model.jine;
}
if(model.zftypeid!=null )
{
SK_Imodel.zftypeid=model.zftypeid;
}
if(model.fkDate!=null )
{
SK_Imodel.fkDate=model.fkDate;
}
if(!string.IsNullOrEmpty(model.remark))
{
SK_Imodel.remark=model.remark;
}
ctx.SubmitChanges();
return string.Empty;
}
catch (Exception ex)
{
return " 修改失败!错误详细信息：" + ex.Message;
}
}
}
#endregion



#region  删除SK_I表Byiid数据
/// <summary>
/// 删除SK_IByiid
/// </summary>
/// <param name="iid">收款单收入明细ID</param>
/// <returns>空或错误</returns>
public string SK_IByiid_Delete(int iid,int ACID)
{
if(iid==null )
{
return "『收款单收入明细ID』不能为空！";
}
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if(ctx.SK_I.Count(p=>p.iid==iid)!=1)
{
return null;
}
SK_I model=ctx.SK_I.Single(p => p.iid== iid);
ctx.SK_I.DeleteOnSubmit(model);
ctx.SubmitChanges();
return string.Empty;
}
catch (Exception ex)
{
return " 删除失败!错误详细信息：" + ex.Message;
}
}
}
#endregion

#region  删除SK_I表Byiid数据[事物用重构]
/// <summary>
/// 删除SK_IByiid[事物用重构]
/// </summary>
/// <param name="iid">收款单收入明细ID</param>
/// <returns>空或错误</returns>
private string SK_IByiid_Delete(int iid,int ACID, CardsServer.DAL.DataClassesDataContext ctx)
{
if(iid==null )
{
return "『收款单收入明细ID』不能为空！";
}
if(ctx.SK_I.Count(p=>p.iid==iid)!=1)
{
return null;
}
SK_I model=ctx.SK_I.Single(p => p.iid== iid);
ctx.SK_I.DeleteOnSubmit(model);
return string.Empty;
}
#endregion



#region  获取SK_I表Byiid数据
/// <summary>
/// 获取SK_IByiid
/// </summary>
/// <param name="iid">收款单收入明细ID</param>
/// <returns>当前表</returns>
public SK_I SK_IByiid_Get(int iid,int ACID)
{
if(iid==null )
{
return null;
}
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if(ctx.SK_I.Count(p=>p.iid==iid)!=1)
{
return null;
}
return ctx.SK_I.SingleOrDefault(p=>p.iid==iid);
}
catch (Exception ex)
{
return null;
}
}
}
#endregion



#region  获取SK_I表数据
/// <summary>
/// 获取SK_I
/// </summary>
/// <param name="sortBy">排序属性名</param>
/// <param name="sortType">排序类型0=升序 1=降序</param>
/// <returns>List<SK_I></returns>
public List<SK_I> SK_I_Get(Expression<Func<SK_I, bool>> predicate , string sortBy,int ACID)
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if (predicate == null)
{
if(string.IsNullOrWhiteSpace(sortBy))
{
return ctx.SK_I.ToList();
}
 else 
{
return ctx.SK_I.OrderBy(sortBy).ToList();
}
}
else
{
if(string.IsNullOrWhiteSpace(sortBy))
{
return ctx.SK_I.Where(predicate).ToList();
}
 else 
{
return ctx.SK_I.Where(predicate).OrderBy(sortBy).ToList();
}
}
}
catch (Exception ex)
{
return null;
}
}
}
#endregion


#region  获取SK_I表数据
/// <summary>
/// 获取SK_I
/// </summary>
/// <param name="sortBy">排序属性名</param>
/// <param name="sortType">排序类型0=升序 1=降序</param>
/// <returns>List<SK_I></returns>
public List<SK_I> SK_I_Get(string sortBy,int ACID)
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
return SK_I_Get(null,sortBy, ACID);
}
catch (Exception)
{
return null;
}
}
}
#endregion


#region  获取SK_I表数据计数
/// <summary>
/// 获取SK_I表数据计数
/// </summary>
/// <returns>List<SK_I></returns>
public int SK_I_GetCount(Expression<Func<SK_I, bool>> predicate,int ACID)
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if (predicate == null)
{
return ctx.SK_I.Count();

}
 else
{
return ctx.SK_I.Where(predicate).Count();
}
}
catch 
{
return 0;
}
}
}
#endregion




#region  获取SK_I分页表数据
/// <summary>
/// 获取SK_I分页表数据
/// </summary>
/// <param name="pageIndex">当前页</param>
/// <param name="pageSize">页大小</param>
/// <param name="sortBy">排序属性名</param>
/// <param name="sortType">排序类型0=升序 1=降序</param>
/// <returns>List<SK_I></returns>
public List<SK_I> SK_I_Getpage(int pageIndex, int pageSize,Expression<Func<SK_I, bool>> predicate ,string sortBy,int ACID)
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if (predicate == null)
{
if(string.IsNullOrWhiteSpace(sortBy))
{
return ctx.SK_I.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
}
 else 
{
return ctx.SK_I.OrderBy(sortBy).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
}
}
else
{
if(string.IsNullOrWhiteSpace(sortBy))
{
return ctx.SK_I.Where(predicate).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
}
 else 
{
return ctx.SK_I.Where(predicate).OrderBy(sortBy).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
}
}
}
catch (Exception ex)
{
return null;
}
}
}
#endregion


#region  批量修改SK_I表数据
/// <summary>
/// 批量修改SK_I
/// </summary>
/// <param name="predicate">Expression<Func<SK_I, bool>></param> 查找表达式树
/// <param name="updater">Expression<Func<SK_I,SK_I>> 更新表达式树</param>
/// <param name="returns">影响记录数</param>
public int SK_I_batchUpdate(Expression<Func<SK_I, bool>> predicate,Expression<Func<SK_I, SK_I>> updater,int ACID)
{
using (TransactionScope ts=new TransactionScope())
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
int ok = ctx.SK_I.Update(predicate, updater);
ts.Complete();
 return ok;
}
catch (Exception ex)
{
return 0;
}
}
}
}
#endregion


#region  批量修改SK_I表数据事物用重构
/// <summary>
/// 批量修改SK_I事物用重构
/// </summary>
/// <param name="predicate">Expression<Func<SK_I, bool>></param> 查找表达式树
/// <param name="updater">Expression<Func<SK_I,SK_I>> 更新表达式树</param>
/// <param name="ctx">数据上下文</param>
/// <param name="returns">影响记录数</param>
private int SK_I_batchUpdate(Expression<Func<SK_I, bool>> predicate,Expression<Func<SK_I, SK_I>> updater,int ACID, CardsServer.DAL.DataClassesDataContext ctx)
{
int ok = ctx.SK_I.Update(predicate, updater);
return ok;
}
#endregion


#region  批量删除SK_I表数据
/// <summary>
/// 批量删除SK_I
/// </summary>
/// <param name="predicate">Expression<Func<SK_I, bool>></param> 查找表达式树
/// <param name="returns">影响记录数</param>
public int SK_I_batchDel(Expression<Func<SK_I, bool>> predicate,int ACID)
{
using (TransactionScope ts=new TransactionScope())
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
int ok = ctx.SK_I.Delete(predicate);
ts.Complete();
 return ok;
}
catch (Exception ex)
{
return 0;
}
}
}
}
#endregion


#region  批量删除SK_I表数据事物用重构
/// <summary>
/// 批量删除SK_I事物用重构
/// </summary>
/// <param name="predicate">Expression<Func<SK_I, bool>></param> 查找表达式树
/// <param name="ctx">数据上下文</param>
/// <param name="returns">影响记录数</param>
private int SK_I_batchDel(Expression<Func<SK_I, bool>> predicate,int ACID, CardsServer.DAL.DataClassesDataContext ctx)
{
int ok = ctx.SK_I.Delete(predicate);
return ok;
}
#endregion


}
}

